package com.shuzhi.stationarysource.modules.job.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.shuzhi.stationarysource.modules.job.domain.AddFixSource;
import com.shuzhi.stationarysource.modules.job.domain.WryBaseInfo;
import com.shuzhi.stationarysource.modules.job.repository.WryBaseInfoRepository;
import com.shuzhi.stationarysource.modules.job.service.WryBaseInfoService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

/**
 * @ClassName WryBaseInfoServiceImpl
 * @Description WryBaseInfoServiceImpl
 * @Author 孙峰
 * @Date 2020/3/24 15:53
 * @Version 1.0
 */
@Service
public class WryBaseInfoServiceImpl implements WryBaseInfoService {

    private WryBaseInfoRepository wryBaseInfoRepository;

    public WryBaseInfoServiceImpl(WryBaseInfoRepository wryBaseInfoRepository) {
        this.wryBaseInfoRepository = wryBaseInfoRepository;
    }

    @Override
    public List<WryBaseInfo> findAllByIsbsts(String isBsts) {
        return wryBaseInfoRepository.findAllByIsbsts(isBsts);
    }
    /**
     * 查询未推送数据
     * @param pageable
     * @return List<AddFixSource>
     */
    @Override
    public List<AddFixSource> findAllNoPush(Pageable pageable) {
        List<Map<String, Object>> push = wryBaseInfoRepository.findAllNoPush(pageable);
        List<AddFixSource> addFixSources1 = JSONObject.parseArray(JSON.toJSONString(push), AddFixSource.class);
        return addFixSources1;
    }

    @Override
    public AddFixSource findById(Long id) {
        return JSONObject.parseArray(JSON.toJSONString(wryBaseInfoRepository.findByIdNoPush(id)),AddFixSource.class).get(0);

    }

}
